<template>
	<view class="page">
		<!-- 收藏 -->
		<view class="navbar">
			共 <text>{{wordList.length}}</text> 词
		</view>

		<view class="list" v-if="list.length>0">
			<block v-for="(item,i) in list" :key="i">
				<view class="date">{{item.date}}</view>

				<!-- 	<u-swipe-action>
					<u-swipe-action-item :options="options1" v-for="(word,j) in item.clientWordDTOS" :key="word.id"
						@click="handleClick($event,word)">
						<view class="item d_flex_b" @click="toExplain(word)">
							<view class="word">{{word.name}}</view>
							<view class="explain flex1" v-if="word.wordExplain">
								<text v-for="(explain,k) in JSON.parse(word.wordExplain)" :key="k">{{explain.chinExplain}}</text>
							</view>
						</view>
					</u-swipe-action-item>
				</u-swipe-action> -->

				<uni-swipe-action>
					<uni-swipe-action-item :right-options="options1" v-for="(word,j) in item.clientWordDTOS" :key="word.id"
						@click="handleClick($event,word)">
						<view class="item d_flex_b" @click="toExplain(word)">
							<view class="word">{{word.name}}</view>
							<view class="explain flex1" v-if="word.wordExplain">
								<text v-for="(explain,k) in JSON.parse(word.wordExplain)" :key="k">{{explain.chinExplain}}</text>
							</view>
						</view>
					</uni-swipe-action-item>
				</uni-swipe-action>

			</block>
		</view>
		<view class="list" v-else>
			<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png"></u-empty>
		</view>
		<view class="page-btn" @click="toReview">
			<view class="btn">巩固错词</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isShow: true,
				list: [],
				wordList: [],
				options1: [{
					text: '移除',
					src: '/static/dd.png',
					style: {
						backgroundColor: '#FF7474',
						flexDirection: 'column',
						fontSize: '24rpx'
					}
				}],

			};
		},
		onShow() {
			this.getList();
		},
		methods: {
			getList() {
				this.$http.get1('/api/client/word/errorWordList').then(res => {
					if (res.code == 200) {
						this.list = res.data;
						this.wordList = [];
						this.list.map(val => {
							this.wordList.push(...val.clientWordDTOS)
						})
					}
				})
			},
			toExplain(item) {
				uni.navigateTo({
					url: '/pagesA/pages/test/explain?id=' + item.id + '&type=2'
				})
			},
			toReview() {
				if (!this.wordList.length) {
					uni.showToast({
						icon: 'none',
						title: `错词本数量${this.wordList.length}`,
					})
					return
				}
				uni.navigateTo({
					url: '/pagesA/pages/test/err-review?type=2'
				})
			},
			handleClick(e, wrod) {
				this.$http.get1('/api/client/word/removeErrorWordId', {
					wordId: wrod.id
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '操作成功'
						})
						this.getList();

					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F2F3F8;
		box-sizing: border-box;
	}

	.navbar {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		font-size: 22rpx;
		color: #333333;
		text-align: center;
		height: 96rpx;
		background: #F9FBFF;
		box-shadow: 0rpx 4rpx 8rpx 2rpx rgba(42, 65, 152, 0.05);
		line-height: 96rpx;
		position: fixed;
		z-index: 999;

		text {
			color: #5480F8;
			margin: 0 8rpx;
		}
	}

	.date {
		margin: 30rpx 0 10rpx 10rpx;
	}

	.u-swipe-action-item {
		margin-bottom: 20rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 8rpx 2rpx rgba(42, 65, 152, 0.05);
		border-radius: 20rpx 20rpx 20rpx 20rpx;
	}

	.list {
		padding: 100rpx 32rpx 190rpx;

		.uni-swipe {
			margin-bottom: 20rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 4rpx 8rpx 2rpx rgba(42, 65, 152, 0.05);
			border-radius: 20rpx 20rpx 20rpx 20rpx;
		}

		.item {
			width: 686rpx;
			padding: 40rpx 30rpx;
			box-sizing: border-box;
			position: relative;
			height: 120rpx;

			.dele-box {
				position: absolute;
				top: 0;
				right: 0;
				width: 96rpx;
				height: 120rpx;
				background: #FF7474;
				border-radius: 0rpx 20rpx 20rpx 0rpx;
				color: #fff;
				font-size: 28rpx;
				text-align: center;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				image {
					width: 32rpx;
					height: 32rpx;
					margin-bottom: 10rpx;
				}
			}

			.word {
				width: 300rpx;
				font-size: 28rpx;
				font-weight: bold;
				color: #333333;
			}

			.explain {
				width: 300rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				font-size: 24rpx;
				font-weight: 400;
				color: #575A64;
				text-align: left;
				padding: 0 0 0 30rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			image {
				width: 40rpx;
				height: 40rpx;
			}
		}
	}

	.page-btn {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 176rpx;
		background: #FFFFFF;
		box-shadow: inset 0rpx 1rpx 0rpx 2rpx rgba(0, 0, 0, 0.1);
		padding: 30rpx 62rpx 56rpx;
		box-sizing: border-box;
		z-index: 19;

		.btn {
			width: 626rpx;
			height: 90rpx;
			background: #5480F8;
			border-radius: 46rpx 46rpx 46rpx 46rpx;
			text-align: center;
			line-height: 90rpx;
			color: #FFFFFF;
			font-size: 32rpx;
		}
	}
</style>